import ServiceLogic from "./net/ServerLogic"

if (cc.sys.isNative) {
    let __handler
    if (window['__errorHandler']) {
        __handler = window['__errorHandler']
    }
    var sendLogMap = {}
    window['__errorHandler'] = function (filepath, lineno, msg, stack) {
        if (__handler) {
            __handler(filepath, lineno, msg, stack)
        }
        if(!msg)
            return
        if(!sendLogMap[msg]) {
            sendLogMap[msg] = true;
            ServiceLogic.submitErrorLog(msg + "\n" + stack)
            return
        }
    }
}

if (cc.sys.isBrowser && !CC_EDITOR) {
    let __handler;
    if (window.onerror) {
        __handler = window.onerror
    }
    window.onerror = function (message, source, lineno, colno, error) {
        if (error != null) {
            //开发时不上传了
            // ServiceLogic.submitErrorLog(error.stack || "")
            return
        }
        if (__handler) {
            __handler(message, source, lineno, colno, error)
        }
    }
}